/******************************************************************************
 * (C) Copyright 2013 Atech-Automotive
 * FILE NAME:    interrupt_vector.c
 * DESCRIPTION:
 * 
 * DATE BEGUN:   2014/08/01
 * BY:           hui.pang
 * PRODUCT NAME:
 * APPLICATION:
 * TARGET H/W:
 * DOC REF:
 *****************************************************************************
 */

/*****************************************************************************
** #include 
*****************************************************************************/
//#include "sys_config.h"
#include "system.h"      

#include "drv_can.h"
#include "drv_timer.h"
#include "drv_SCI.h"
#include "drv_RTI.h"
/*****************************************************************************
** #define
*****************************************************************************/


/*****************************************************************************
** typedef
*****************************************************************************/
typedef void (*near tIsrFunc)(void);

/*****************************************************************************
** global variable
*****************************************************************************/


/*****************************************************************************
** static variables
*****************************************************************************/


/*****************************************************************************
** static constants
*****************************************************************************/


/*****************************************************************************
** static function prototypes
*****************************************************************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
static void MCU_init_reset( void );
#pragma CODE_SEG DEFAULT

#pragma CODE_SEG BOOT_SEG
void MCU_init_reset_by_bootloader( void );
#pragma CODE_SEG DEFAULT

/*****************************************************************************
** function prototypes
*****************************************************************************/
 extern void near _Startup( void );
 extern __interrupt void Comm_isr_SCI0(void);
/****************************************************************************/
/****************************************************************************/
/**
 * Function Name: MCU_init_reset_by_bootloader
 * Description: none
 *
 * Param:   none
 * Return:  none
 * Author:  2014/08/01, hui.pang create this function
 ****************************************************************************/
#pragma CODE_SEG BOOT_SEG 

void MCU_init_reset_by_bootloader( void )
{
    MCU_init_reset();
}

#pragma CODE_SEG DEFAULT


/****************************************************************************/
/**
 * Function Name: MCU_init_reset
 * Description: none
 *
 * Param:   none
 * Return:  none
 * Author:  2014/08/01, hui.pang create this function
 ****************************************************************************/ 
#pragma CODE_SEG __NEAR_SEG NON_BANKED
static void __interrupt  MCU_init_reset( void )
{
  /*  Initialization of memory configuration */
  /* MMCCTL1: NVMRES=0 */
  MMCCTL1 = 0x00U;                                      
  /* PKGCR: APICLKS7=0,PKGCR2=1,PKGCR1=1,PKGCR0=0 */
  PKGCR = 0x03U;                                      
  /* DIRECT: DP15=0,DP14=0,DP13=0,DP12=0,DP11=0,DP10=0,DP9=0,DP8=0 */
  DIRECT = 0x00U;                                      
  /* IVBR: IVB_ADDR=0x14 */
  IVBR = 0x40U;                                      
  /* ECLKCTL: NECLK=1,NCLKX2=1,DIV16=0,EDIV4=0,EDIV3=0,EDIV2=0,EDIV1=0,EDIV0=0 */
  ECLKCTL = 0xC0U;                                      
  /* Jump to the default entry point */
  /*lint -save  -e950 Disable MISRA rule (1.1) checking. */
  asm jmp _Startup;
  /*lint -restore Enable MISRA rule (1.1) checking. */
} /*MCU_init*/

#pragma CODE_SEG DEFAULT

/****************************************************************************/
/**
 * Function Name: Cpu_Interrupt
 * Description: none
 *
 * Param:   none
 * Return:  none
 * Author:  2014/08/01, hui.pang create this function
 ****************************************************************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
/*
** ===================================================================
**     Interrupt handler : isr_default
**
**     Description :
**         User interrupt service routine. 
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
__interrupt void isr_default(void)
{
    /*lint -save -e950 Disable MISRA rule (1.1) checking. */
    asm(BGND);
    /*lint -restore Enable MISRA rule (1.1) checking. */
}

#pragma CODE_SEG DEFAULT


/*lint -restore Enable MISRA rule (8.10) checking. */

/*lint -save  -e950 Disable MISRA rule (1.1) checking. */
/* Initialization of the CPU registers in FLASH */

/* NVFSEC: KEYEN1=0,KEYEN0=1,RNV5=1,RNV4=1,RNV3=1,RNV2=1,SEC1=1,SEC0=0 */
//static const unsigned char NVFSEC_INIT @0x0000FF0FU = 0x7EU;
/*lint -restore Enable MISRA rule (1.1) checking. */



 
/*******************************************************************************/
/* Interrupt vector table */
#ifndef UNASSIGNED_ISR
  #define UNASSIGNED_ISR isr_default   /* unassigned interrupt service routine */
#endif

/* ISR prototype */
typedef void (*near tIsrFunc)(void);
/*lint -save  -e950 Disable MISRA rule (1.1) checking. */
static const tIsrFunc _InterruptVectorTable[] @0x4080U = { /* Interrupt vector table */
/*lint -restore Enable MISRA rule (1.1) checking. */
  /* ISR name                               No.  Address  Name          Description */
  &UNASSIGNED_ISR,                       /* 0x40  0xFF80   ivVsi         unused by PE */
  &UNASSIGNED_ISR,                       /* 0x41  0xFF82   ivVportad     unused by PE */
  &UNASSIGNED_ISR,                       /* 0x42  0xFF84   ivVatdcompare unused by PE */
  &UNASSIGNED_ISR,                       /* 0x43  0xFF86   ivVReserved60 unused by PE */
  &UNASSIGNED_ISR,                         /* 0x44  0xFF88   ivVapi        unused by PE */
  &UNASSIGNED_ISR,                       /* 0x45  0xFF8A   ivVlvi        unused by PE */
  &UNASSIGNED_ISR,                       /* 0x46  0xFF8C   ivVReserved57 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x47  0xFF8E   ivVportp      unused by PE */
  &UNASSIGNED_ISR,                       /* 0x48  0xFF90   ivVReserved55 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x49  0xFF92   ivVReserved54 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x4A  0xFF94   ivVReserved53 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x4B  0xFF96   ivVReserved52 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x4C  0xFF98   ivVReserved51 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x4D  0xFF9A   ivVReserved50 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x4E  0xFF9C   ivVReserved49 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x4F  0xFF9E   ivVReserved48 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x50  0xFFA0   ivVReserved47 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x51  0xFFA2   ivVReserved46 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x52  0xFFA4   ivVReserved45 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x53  0xFFA6   ivVReserved44 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x54  0xFFA8   ivVReserved43 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x55  0xFFAA   ivVReserved42 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x56  0xFFAC   ivVReserved41 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x57  0xFFAE   ivVReserved40 unused by PE */
  &drv_can_v_txISR,                      /* 0x58  0xFFB0   ivVcantx      unused by PE */
  &drv_can_v_rxISR,                      /* 0x59  0xFFB2   ivVcanrx      unused by PE */
  &drv_can_v_errorISR,                   /* 0x5A  0xFFB4   ivVcanerr     unused by PE */
  &drv_can_v_wakeUpISR,                  /* 0x5B  0xFFB6   ivVcanwkup    unused by PE */
  &UNASSIGNED_ISR,                       /* 0x5C  0xFFB8   ivVflash      unused by PE */
  &UNASSIGNED_ISR,                       /* 0x5D  0xFFBA   ivVflashfd    unused by PE */
  &UNASSIGNED_ISR,                       /* 0x5E  0xFFBC   ivVReserved33 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x5F  0xFFBE   ivVspi1       unused by PE */
  &UNASSIGNED_ISR,                       /* 0x60  0xFFC0   ivVReserved31 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x61  0xFFC2   ivVReserved30 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x62  0xFFC4   ivVReserved29 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x63  0xFFC6   ivVcpmuplllck unused by PE */
  &UNASSIGNED_ISR,                       /* 0x64  0xFFC8   ivVcpmuocsns  unused by PE */
  &UNASSIGNED_ISR,                       /* 0x65  0xFFCA   ivVReserved26 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x66  0xFFCC   ivVacmp       unused by PE */
  &UNASSIGNED_ISR,                       /* 0x67  0xFFCE   ivVportj      unused by PE */
  &UNASSIGNED_ISR,                       /* 0x68  0xFFD0   ivVReserved23 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x69  0xFFD2   ivVatd        unused by PE */
  &Comm_isr_SCI1,                       /* 0x6A  0xFFD4   ivVsci1       unused by PE */
  &Comm_isr_SCI0,                       /* 0x6B  0xFFD6   ivVsci0       unused by PE */
  &UNASSIGNED_ISR,                       /* 0x6C  0xFFD8   ivVspi0       unused by PE */
  &UNASSIGNED_ISR,                       /* 0x6D  0xFFDA   ivVReserved18 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x6E  0xFFDC   ivVReserved17 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x6F  0xFFDE   ivVtimovf     unused by PE */
  &UNASSIGNED_ISR,                       /* 0x70  0xFFE0   ivVReserved15 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x71  0xFFE2   ivVReserved14 unused by PE */
  &UNASSIGNED_ISR,                       /* 0x72  0xFFE4   ivVtimch5     unused by PE */
  &UNASSIGNED_ISR,                       /* 0x73  0xFFE6   ivVtimch4     unused by PE */
  &UNASSIGNED_ISR,                       /* 0x74  0xFFE8   ivVtimch3     unused by PE */
  &UNASSIGNED_ISR,                       /* 0x75  0xFFEA   ivVtimch2     unused by PE */
  &UNASSIGNED_ISR,                       /* 0x76  0xFFEC   ivVtimch1     unused by PE */
  &UNASSIGNED_ISR,                            /* 0x77  0xFFEE   ivVtimch0     unused by PE */
  &isr_RunRTI,                           /* 0x78  0xFFF0   ivVrti        used by PE */
  &UNASSIGNED_ISR,                       /* 0x79  0xFFF2   ivVirq        unused by PE */
  &UNASSIGNED_ISR,                       /* 0x7A  0xFFF4   ivVxirq       unused by PE */
  &UNASSIGNED_ISR,                       /* 0x7B  0xFFF6   ivVswi        unused by PE */
  &UNASSIGNED_ISR                        /* 0x7C  0xFFF8   ivVtrap       unused by PE */
};

/*lint -save  -e950 Disable MISRA rule (1.1) checking. */
static const tIsrFunc _ResetVectorTable[] @0xFFFAU = { /* Reset vector table */
/*lint -restore Enable MISRA rule (1.1) checking. */
  /* Reset handler name                    Address Name            Description */
  &MCU_init_reset,                         /* 0xFFFA  ivVcop          used by PE */
  &MCU_init_reset,                         /* 0xFFFC  ivVclkmon       unused by PE */
  &MCU_init_reset                          /* 0xFFFE  ivVreset        used by PE */
};

/*************************end of s12g128_vector.c*****************************/

/******************************************************************************
 Revision Notes:

For each change to this file, be sure to record:
1. Who made the change and when the change was made.
2. Why the change was made and the intended result.

  Date     By     Reason For Change
mm/dd/yy  XXX     -----------------

******************************************************************************/
/*******************************************************************************/
